package cn.project.lemontree.controller;

import cn.project.lemontree.aop.SystemControllerLog;
import cn.project.lemontree.bean.Parent;
import cn.project.lemontree.bean.Sign_in;
import cn.project.lemontree.service.Sign_inService;
import cn.project.lemontree.tools.CommonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;


@RestController
@RequestMapping("/signIn")
@Api(tags = "签到管理模块")
@CrossOrigin
public class Sign_inController {

    @Resource
    private Sign_inService signInService;

    @ApiOperation("分页查询签到信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name="page",value="页码",required=true,dataTypeClass = int.class,example = "1"),
            @ApiImplicitParam(name="size",value="每页行数",required=true,dataTypeClass = int.class,example = "10"),
            @ApiImplicitParam(name="parentName",value="家长姓名",required=false,dataTypeClass = String.class)
    })
    @GetMapping("/listpage")
    public CommonResult listpage(int page, int size, String parentName){
        Map<String,Object> map = new HashMap<>();
        map.put("count",signInService.count(parentName));
        map.put("data",signInService.listPage(page,size,parentName));
        return CommonResult.success(map);
    }

    @SystemControllerLog(description = "删除签到信息")
    @ApiOperation("删除签到信息")
    @GetMapping("/remove")
    public CommonResult remove(@RequestParam("sign_in_id") int sign_in_id){
        return CommonResult.success(signInService.removeById(sign_in_id));
    }

    @SystemControllerLog(description = "添加签到信息")
    @ApiOperation("添加签到信息")
    @PostMapping("/save")
    public CommonResult save(@RequestBody Sign_in signIn,@RequestParam Integer parentId){
        Parent parent = new  Parent();
        parent.setParentId(parentId);
        signIn.setParent(parent);
        return CommonResult.success(signInService.save(signIn));
    }

}

